package cn.tedu.sync.reentrant;

import java.util.concurrent.locks.ReentrantLock; // JUC

public class ReentrantDemo {
    private final ReentrantLock lock = new ReentrantLock(true);

    public static void main(String[] args) {
        ReentrantDemo demo = new ReentrantDemo();
        demo.methodA();

    }

    public void methodA() {
        lock.lock();
        try {
            System.out.println("进入methodA");
            methodB();
        } finally {
            System.out.println("释放A");
            lock.unlock();
        }
    }

    public void methodB() {
        lock.lock();
        try {
            System.out.println("进入methodB");
        } finally {
            System.out.println("释放B");
            lock.unlock();
        }
    }
}
